package com.agri.controller;

import com.agri.result.Result;
import com.agri.service.CropCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 农产品分类控制器
 * 提供农产品分类的CRUD操作和查询接口
 *
 * @author Agri-Fin-Sale Team
 * @since 2025-11-05
 */
@RestController
@RequestMapping("/crop/category")
public class CropCategoryController {
    @Autowired
    private CropCategoryService cropCategoryService;

    /**
     * 查询所有分类列表
     */
    @GetMapping("/list")
    public Result<?> list() {
        return cropCategoryService.listCategories();
    }

    /**
     * 根据ID获取分类详情
     */
    @GetMapping("/{id}")
    public Result<?> getById(@PathVariable Long id) {
        return cropCategoryService.getCategoryById(id);
    }

    /**
     * 根据父级ID查询子分类
     */
    @GetMapping("/parent/{parentId}")
    public Result<?> getByParent(@PathVariable Long parentId) {
        return cropCategoryService.getCategoriesByParent(parentId);
    }

    /**
     * 查询一级分类
     */
    @GetMapping("/level1")
    public Result<?> getLevel1Categories() {
        return cropCategoryService.getLevel1Categories();
    }
}